// pages/f_person_info/index.js
Page({

  /**
   * 页面的初始数据
   */
	data: {
		U_Headimgurl: '../../images/w/2.png',
		U_Nickname: '匿名',
		Money:'',

		SexList: ['男', '女'],
		modalHidden: true,
		modalValue: '',

		TabList: [
			{
				"id": 1,
				"icon": "../../images/w/5.png",
				"text": "性别",
				"text2": "请填写",
			},
			{
				"id": 2,
				"icon": "../../images/w/6.png",
				"text": "年龄",
				"text2": "请填写",
			},
			{
				"id": 3,
				"icon": "../../images/w/7.png",
				"text": "QQ",
				"text2": "请填写",
			},
			{
				"id": 4,
				"icon": "../../images/w/8.png",
				"text": "邮箱",
				"text2": "请填写",
			},
		]
	},

  /**
   * 生命周期函数--监听页面加载
   */
	onLoad: function (options) {
		this.requestNetUserDetail();

	},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
	onReady: function () {

	},


  /**
   * 生命周期函数--监听页面显示
   */
	onShow: function () {
    console.log("ssss");
    var _this = this;
    console.log(getApp().data.Token),
    wx.request({
      url: 'https://www.chnode.xyz/api/Balance.ashx?',
      data:{
        DataType:"MyBalance",
        Token: getApp().data.Token,
      },
      success:function(res){
        console.log(res.data.data.U_Blance);
        _this.setData({
          Money: res.data.data.U_Blance,
        })
      }
    })
	},

  /**
   * 生命周期函数--监听页面隐藏
   */
	onHide: function () {

	},

  /**
   * 生命周期函数--监听页面卸载
   */
	onUnload: function () {

	},

	/**
 * 网络请求--个人信息
 */
	requestNetUserDetail: function () {
		var _this = this;
		wx.request({
			url: 'https://www.chnode.xyz/api/My.ashx?DataType=UserDetail&Token=' + getApp().data.Token,
			success: function (res) {
        console.log("aaaaaa");
        console.log(res);
				if (res.data.isok == 'true') {
					var tempUserDetail = res.data.data;
					_this.data.TabList[0].text2 = tempUserDetail.U_Gender;
					if (tempUserDetail.U_Age != '')
						_this.data.TabList[1].text2 = tempUserDetail.U_Age;
					if (tempUserDetail.U_QQ != '')
						_this.data.TabList[2].text2 = tempUserDetail.U_QQ;
					if (tempUserDetail.U_Email != '')
						_this.data.TabList[3].text2 = tempUserDetail.U_Email;
					_this.data.U_Headimgurl = tempUserDetail.U_Headimgurl;
					_this.data.U_Nickname = tempUserDetail.U_Nickname;
					_this.setData({
						TabList: _this.data.TabList,
						U_Headimgurl: _this.data.U_Headimgurl,
						U_Nickname: _this.data.U_Nickname
					})
				}
			},
		})
	},

	/**
	 * 点击事件--条目设置
	 */
	btnEventTab: function (e) {
		var _this = this;
		var index = e.currentTarget.dataset.id;
		if (index == 1)
			wx.showActionSheet({
				itemList: _this.data.SexList,
				success: function (res) {
					console.log(_this.data.SexList[res.tapIndex])
          _this.data.TabList[0].text2 = _this.data.SexList[res.tapIndex];
          _this.setData({
            TabList: _this.data.TabList
          })
      _this.requestNetUserUpdate()
				},
			})
		else {
			_this.setData({
				modalHidden: false,
				modalType: index,
				modalTitle: index == 2 ? '修改年龄' : index == 3 ? '修改QQ' : '修改邮箱',
				modalPlaceholder: index == 2 ? '请输入年龄' : index == 3 ? '请输入QQ' : '请输入邮箱',
				modalValue: "",
				modalInputType: index == 2 ? 'number' : index == 3 ? 'text' : 'text',
			})
		}
	},

	/**
	 * Model 输入监听
	 */
	bindModalInput: function (res) {
		this.setData({
			modalValue: res.detail.value
		})
	},

  /**
   * Modal 确认按钮
   */
	btnEventModalConfirm: function () {
		var _this = this;
		if (_this.data.modalType == 2) {
			_this.data.TabList[1].text2 = _this.data.modalValue
		} else if (_this.data.modalType == 3) {
			_this.data.TabList[2].text2 = _this.data.modalValue
		} else if (_this.data.modalType == 4) {
			_this.data.TabList[3].text2 = _this.data.modalValue
		}
		_this.setData({
			TabList: _this.data.TabList,
			modalHidden: true,
			modalValue: "",
		})
		_this.requestNetUserUpdate()
	},

  /**
   * Modal 取消按钮
   */
	btnEventModalCancel: function () {
		this.setData({
			modalHidden: true,
			modalValue: "",
		})
	},


	/**
	 * 网络请求--修改个人信息
	 */
	requestNetUserUpdate: function () {
		var _this = this;
		wx.request({
			url: 'https://www.chnode.xyz/api/My.ashx?DataType=UserUpdate',
			data: {
				'Token': getApp().data.Token,
				'Sex': _this.data.TabList[0].text2 == '男' ? '1' : '2',
				'Email': _this.data.TabList[3].text2,
				'Age': _this.data.TabList[1].text2,
				'QQ': _this.data.TabList[2].text2
			},
			success: function (res) {
				console.log(res.data)
			}
		})
	},


})